package com.rrqs.activity;


import com.zadtek.xmqishi.R;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

/**
 * 排行榜
 *
 * @author kuyukeji
 */
public class PaihFragment extends FragmentActivity {

    private ImageView backid;
    private TextView topview; // 标题
    private RadioGroup radioGroup, tab_time;
    private FragmentTransaction fragmentTrans;

    private RadioButton radio_nopay;    //配送评分
    private PaihChildFragment fragment;    //排行

    String time = "1";
    String state = "1";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_paih);
        radio_nopay = (RadioButton) findViewById(R.id.radio_nopay);
        backid = (ImageView) findViewById(R.id.backid);
        backid.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        topview = (TextView) findViewById(R.id.topview);
        topview.setText("排行榜");

        radioGroup = (RadioGroup) findViewById(R.id.tab_radio);
        tab_time = (RadioGroup) findViewById(R.id.tab_time);

        fragmentTrans = getSupportFragmentManager().beginTransaction();
        if (fragment == null) {    //默认显示第一个
            fragment = new PaihChildFragment();
            fragment.setState("1");
            fragment.setState("1");
            fragmentTrans.add(R.id.layout_content, fragment).commit();
        }

        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.type1:
                        state = "1";
                        fragment = new PaihChildFragment();
                        fragment.setState(state);
                        fragment.setTime(time);
                        getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
                        break;

                    case R.id.type2:
                        state = "2";
                        fragment = new PaihChildFragment();
                        fragment.setState(state);
                        fragment.setTime(time);
                        getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
                        break;

                    case R.id.type3:
                        state = "3";
                        fragment = new PaihChildFragment();
                        fragment.setState(state);
                        fragment.setTime(time);
                        getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
                    case R.id.type4:
                        state = "4";
                        fragment = new PaihChildFragment();
                        fragment.setState(state);
                        fragment.setTime(time);
                        getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
                        break;
                }
            }
        });
        tab_time.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.toady:
                        time = "1";
                        fragment = new PaihChildFragment();
                        fragment.setState(state);
                        fragment.setTime(time);
                        getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
                        break;

                    case R.id.yesterday:
                        time = "2";
                        fragment = new PaihChildFragment();
                        fragment.setState(state);
                        fragment.setTime(time);
                        getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
                        break;

                    case R.id.mouth:
                        time = "3";
                        fragment = new PaihChildFragment();
                        fragment.setState(state);
                        fragment.setTime(time);
                        getSupportFragmentManager().beginTransaction().replace(R.id.layout_content, fragment).commit();
                        break;
                }
            }
        });
    }

//	private DatePicker findDatePicker(ViewGroup group) {
//        if (group != null) {
//            for (int i = 0, j = group.getChildCount(); i < j; i++) {
//                View child = group.getChildAt(i);
//                if (child instanceof DatePicker) {
//                    return (DatePicker) child;
//                } else if (child instanceof ViewGroup) {
//                    DatePicker result = findDatePicker((ViewGroup) child);
//                    if (result != null)
//                        return result;
//                }
//            }
//        }
//        return null;
//    }

}
